"use strict";
cc._RF.push(module, '60123eU+S5OEKFy+vV0uBwr', 'SoundUtil');
// Script/Ssg/Utils/SoundUtil.js

"use strict";

var QQSound = require("QQSound");
var NativeSound = require("NativeSound");

/**音乐状态对应的值
 * cc.audioEngine.AudioState.ERROR： -1
 * cc.audioEngine.AudioState.INITIALZING ： 0
 * cc.audioEngine.AudioState.PLAYING ： 1
 * cc.audioEngine.AudioState.PAUSED ： 2
 */

window.SoundUtil = function () {

    var isOpenMusic = true;
    var isOpeneffect = false;
    var playingMusicName = null;

    var _static = {

        /**
         * 是否开启音乐
         * @param isOpenMusic
         */
        openMusic: function openMusic(isOpenMusic) {
            this.isOpenMusic = isOpenMusic;
            if (!isOpenMusic) {
                this.pauseMusic();
            } else {
                this.resumeMusic();
            }
        },

        /**
         * 是否开启音效
         * @param isOpenMusic
         */
        openEffect: function openEffect(isOpeneffect) {
            this.isOpeneffect = isOpeneffect;
        },

        /**
         * url: 音乐文件路径
         * isAssets: 音乐文件是否存放在assets文件夹目录或子文件夹目录下。如果为true，目录必须以assets为根目录
         */
        playEffect: function playEffect(fileName) {
            if (!isOpeneffect) {
                return;
            }
            if (fileName === "") {
                return;
            }
            if (SystemInfo.getPlatform() == 'qqPlay') {
                QQSound.playEffect(fileName);
            } else {
                NativeSound.playEffect(fileName);
            }
        },

        /**
         * 停止当前音乐
         */
        stopMusic: function stopMusic() {
            if (!this.playingMusicName) {
                return;
            }
            if (SystemInfo.getPlatform() == 'qqPlay') {
                QQSound.stopMusic();
            } else {
                NativeSound.stopMusic();
            }
        },

        /**
         * 播放背景音乐
         * @param fileName
         */
        playMusic: function playMusic(fileName, isLoop) {
            if (fileName == '' || this.playingMusicName == fileName || !this.isOpenMusic) {
                return;
            }
            this.stopMusic();
            if (SystemInfo.getPlatform() == 'qqPlay') {
                QQSound.playMusic(fileName, isLoop);
            } else {
                NativeSound.playMusic(fileName, isLoop);
            }
        },

        /**
         * 恢复播放
         */
        resumeMusic: function resumeMusic(fileName) {
            if (SystemInfo.getPlatform() == 'qqPlay') {
                QQSound.resumeMusic(fileName);
            } else {
                NativeSound.resumeMusic(fileName);
            }
        },

        /**
         * 暂停播放
         * @param fileName
         */
        pauseMusic: function pauseMusic(fileName) {
            if (SystemInfo.getPlatform() == 'qqPlay') {
                QQSound.pauseMusic(fileName);
            } else {
                NativeSound.pauseMusic(fileName);
            }
        }

    };

    return _static;
}();

module.exports = SoundUtil;

cc._RF.pop();